<template>
	<view>
		<view v-if="dataBuffer">
			<view class="item" v-for="(res, index) in siteList" :key="res.id">
				<u-icon name="close-circle-fill" :size="40" color="#ff5500" :index="res.id"></u-icon>
				<view class="top" @click="choiceAddress(index)">
					<view class="name">{{ res.username }}</view>
					<view class="phone">{{ res.userphone }}</view>
					<view class="tag">
						<text class="red" v-if="res.status == 1">默认</text>
					</view>
				</view>
				<view class="bottom">
					{{res.location+res.useraddress}}
					<u-icon name="edit-pen" :size="40" color="#999999" :index="res.id"></u-icon>
				</view>
			</view>
		</view>
		<view v-else>
			暂无收货地址信息!
		</view>
		<view class="addSite_box">
			<view class="addSite" @tap="toAddSite">
				<view class="add">
					<u-icon name="plus" color="#ffffff" class="icon" :size="30"></u-icon>新建收货地址
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				siteList: [{
					status: 1,
					label: '公司',
					username: '亚瑟',
					userphone: 13716078900,
					location: '北京市市辖区朝阳区',
					useraddress: '五方桥基地'
				}], //初始化地址数据
				dataBuffer: true
			};
		},
		onShow() {
			let userInfo = this.$tool.islogin()
			if (userInfo != false) {
				// 2.获取用户的收获地址数据
				let uid = userInfo.uid
				this.getaddresslist({
					uid
				})
			}
		},
		methods: {
			choiceAddress(index){
				uni.navigateTo({
					url:"../order/order?address="+JSON.stringify(this.siteList[index])
				})
				console.log(index);
			},
			getaddresslist(data) {
				this.$api.reqaddresslist(data)
					.then(res => {
						this.siteList = res.list
						console.log(res)
					}).catch(err => console.log(err))
			},
			// 跳转到新增地址页面
			toAddSite() {
				uni.navigateTo({
					url: './addSite'
				})
			}
		}
	};
</script>

<style lang="scss" scoped>
	// 引入样式
	@import '@/static/css/address.scss';
</style>
